const db = wx.cloud.database()
const App = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    myInfo: {
      avatarUrl: "",
      nickName: "",
      identity: "",
      college: "",
      gender: "",
    },
    // tabbar 
    list: [{
        pagePath: '/pages/administrator/home/index',
        iconPath: "../../images/icon/home.png",
        color: "text-blue",
        text: '首页',
      },
      {
        pagePath: '/pages/administrator/management/list/index',
        iconPath: "../../images/icon/practice.png",
        color: "text-gray",
        text: '管理',
      },
      {
        pagePath: '/pages/administrator/message/list/index',
        iconPath: "../../images/icon/teaching.png",
        color: "text-gray",
        text: '消息',
      },
      {
        pagePath: '/pages/administrator/my/index',
        iconPath: "../../images/icon/my-action.png",
        color: "text-gray",
        text: '我的',
      }
    ],
    userContentList: [{
        id: 0,
        title: "",
        text: "",
        iconbg: "#D6F4FA",
        iconcolor: "#31C9E8",
        icon: "icon-shenfenleibie",
        icon2: "",
      },
      {
        id: 1,
        title: "学院",
        text: "班级",
        iconbg: "#FFEDD4 ",
        iconcolor: "#FFA726",
        icon: "icon-xueyuan",
        icon2: "",
      }, {
        id: 2,
        title: "科大",
        text: "",
        iconbg: "#FAD5E8",
        iconcolor: "#E72F8C",
        icon: "icon-mingxiaomingshi",
        icon2: "",
      }, {
        id: 3,
        title: "实训",
        text: "基地",
        iconbg: "#D6FADB",
        iconcolor: "#31E749",
        icon: "icon-shenfenleibie",
        icon2: "",
      },
    ],
    // 身份信息
    identityArray: [{
      name: '学生',
      id: 'Students'
    }, {
      name: '教师',
      id: 'Teachers'
    }, {
      name: '管理员',
      id: 'Administrator'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let get_openid = App.cache.getOpenID()
    console.log('用户openid', get_openid);
    this.setData({
      get_openid: get_openid
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    // 路由回来刷新页面
    this.myInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  // 个人信息总览 start
  myInfo() {
    let that = this
    let identityArray = that.data.identityArray
    // 获取用户信息
    let UserInfo = App.cache.getUserInfo()
    console.log('获取用户信息:', UserInfo);
    // 根据身份id获取对应的身份
    let identityobj = identityArray.find(function (identityobj) {
      return identityobj.id === UserInfo.identityId
    })
    console.log("身份 ", identityobj.name);
    this.setData({
      ['myInfo.avatarUrl']: UserInfo.avatarUrl,
      ['myInfo.nickName']: UserInfo.nickName,
      ['myInfo.college']: UserInfo.collegeId,
      ['myInfo.identity']: identityobj.name,
      'userContentList[0].title': identityobj.name
    })
  },
  // 个人信息总览 end
  // 个人信息弹窗 start
  showModal(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  // 个人信息弹窗 end
  // 日志弹窗 start

  // 日志弹窗 end

  // 复制gitee地址
  CopyLink(e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.link,
      success: res => {
        wx.showToast({
          title: '地址已复制,请打开浏览器查看',
          icon: "none",
          duration: 1000,
        })
      }
    })
  },
      // 关于程序
      about() {
        App.route.navTo('/pages/about/index')
      },
  // 路由跳转修改个人信息
  updateMy() {
    App.route.navTo('/pages/updateMy/index')
  },
  myclass() {
    App.route.navTo('/pages/myclass/list/index')
  },
    // 日志
    log(){
      App.route.navTo('/pages/log/index')
    }
})